﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BusinessObjects.BO_GetObjects;
using LibraryO2S;
using BusinessObjects;

public partial class controls_admin_ContactDetails : Pages_Base
{
    protected void Page_Load(object sender, EventArgs e)
    {
        base.removeHGC(divMessage);
        if (!IsPostBack)
            loadContact();
    }
    private void loadContact()
    {
        try
        {
            base.OpenConnection();
            DataTable objDT = null;
            if (Request["id"] != null)
                objDT = BO_ContactUs.Search(Convert.ToInt32(Request["id"].ToString()));
            if (objDT != null && objDT.Rows.Count > 0)
            {
                CONTACT_TITLE.InnerHtml = objDT.Rows[0]["CONTACT_TITLE"].ToString();
                CONTACT_DETAIL.InnerHtml = objDT.Rows[0]["CONTACT_DETAIL"].ToString();
            }
            else
            {
                CONTACT_TITLE.InnerText = "";
                CONTACT_DETAIL.InnerText = "";
                btnDel.Visible = false;
                divMessage.InnerHtml = O2S_Message.Warning("Cảnh Báo", "Dữ liệu đã bị xóa bạn nên quay lại trang chủ !");
            }
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = O2S_Message.Error("Lỗi", "Có lỗi xảy ra !<br />" + ex.Message);
        }
        finally { base.CloseConnection(); }
    }
    protected void btnDel_Click(object sender, EventArgs e)
    {
        try
        {
            if (Request["id"] != null)
            {
                base.OpenConnection();
                if (BO_ContactUs.Delete(Convert.ToInt32(Request["id"])))
                    loadContact();
                else
                    divMessage.InnerHtml = O2S_Message.Warning("Thông Báo", "Sự cố đường truyền mong bạn trở lại sau.");
            }
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = O2S_Message.Error("Lỗi", "Có lỗi xảy ra !<br />" + ex.Message);
        }
        finally { base.CloseConnection(); }
    }
}
